/**
 * DWR remote combobox
 * 
 * <pre>
 *  var cbx = new CQCIS.form.DWRComboBox({
 *              ds : {call: dwr.method, 
 *                    params: 'xxx' or ['aaa','bbb']
 *                    fields : ['key','label']
 *                    }, 
 *              emptyText : '请选择xx', 
 *              displayField : 'label'});
 * </pre>
 * 
 * @author liuhz
 */
CQCIS.form.DWRComboBox = Ext.extend(Ext.form.ComboBox, {
	/**
	 * @cfg {CQCIS.data.DWRStore} CQCIS.data.DWRStore or config
	 */
	/**
	 * @cfg {emptyText} string 提示信息
	 */
	/**
	 * @cfg {displayField} string 显示字段
	 */
	/**
	 * @cfg {valueField} string 值字段
	 */
	/**
	 * @cfg {lazyInit} boolean 是否延时加载 默认为true
	 */
	editable : false,
	typeAhead : false,
	triggerAction : 'all',
	selectOnFocus : true,
	mode : 'remote',
	valueField : 'key',
	displayField : 'label',
    resizable: true,
	initComponent : function() {
		if (this.ds instanceof CQCIS.data.DWRStore) {
			this.store = this.ds;
			delete this.ds;
		} else {
			this.store = new CQCIS.data.DWRStore( {
				dwr : {
					call : this.ds.call,
					params : this.ds.params
				},
                listeners: this.ds.listeners || null,
				fields : this.fields,
				defaultItems : this.defaultItems
			});
			delete this.ds;
		}
		if (!this.width) {
			this.width = 100;
		}

		CQCIS.form.DWRComboBox.superclass.initComponent.call(this);
	},
	onRender : function(ct, position) {
		CQCIS.form.DWRComboBox.superclass.onRender.call(this, ct, position);
		if (!this.lazyInit) {
			this.doQuery(this.allQuery, true);
		}

		this.store.on('load', function() {
			if (this.getValue()) {
				this.setValue(this.getValue());
			}
		}, this);
	},
    getStore : function() {
        return this.store;
    }
});
Ext.reg('rcombo', CQCIS.form.DWRComboBox);
